package com.huawei.appgallery.updatemanager.ui.fragment;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.HeaderViewListAdapter;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.RelativeLayout;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.widget.CardListAdapter;
import com.huawei.appgallery.foundation.ui.framework.fragment.AppListFragment;
import com.huawei.appgallery.foundation.ui.framework.titleframe.bean.BaseTitleBean;
import com.huawei.appgallery.foundation.ui.framework.widget.NetworkRemindBar;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean.a;
import com.huawei.appgallery.updatemanager.api.UpdateMgrFragmentProtocol;
import com.huawei.appgallery.updatemanager.api.UpdateMgrFragmentProtocol.Request;
import com.huawei.appgallery.updatemanager.ui.cardkit.bean.UpdateRecordCardBean;
import com.huawei.appgallery.updatemanager.ui.cardkit.card.PreDownloadSwitchStateCard;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import huawei.widget.HwButton;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import o.azb;
import o.ccv;
import o.cep;
import o.chd;
import o.chm;
import o.chz;
import o.cia;
import o.cjd;
import o.cje;
import o.cjf;
import o.cjk;
import o.cjl;
import o.cjm;
import o.ckm;
import o.BaseRequest;
import o.czi;
import o.czk$a;
import o.czk$b;
import o.czk$c;
import o.czk$e;
import o.czk.g;
import o.czr;
import o.czx;
import o.czz;
import o.dao;
import o.dbb;
import o.dbc;
import o.dbd;
import o.dbe;
import o.dbn;
import o.ContentManager;
import o.epv;
import o.eqh;
import o.erm;
import o.ActivityUtil;
import o.ll;

public class UpdateManagerFragment extends AppListFragment<UpdateMgrFragmentProtocol> {
    private View ʹ;
    private boolean ʻˊ = true;
    private ExecutorService ʻˋ = null;
    private cjf ʼˋ;
    protected Handler ˊ;
    private LinearLayout ॱॱ;
    private dbd ᐝ;
    private boolean ꜝ = false;
    private czz ꜞॱ;
    private RelativeLayout ꜟॱ;
    private boolean ꞌॱ = false;
    private View ﹳ;
    private PreDownloadSwitchStateCard ﹳॱ;
    private BroadcastReceiver ﹶ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ UpdateManagerFragment ˊ;

        {
            this.ˊ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (this.ˊ.ᐝ == null || this.ˊ.י == null) {
                czi.ˎ.ˏ("UpdateManagerFragment", "param error, updateRecordManager or provider is null!");
                this.ˊ.ˋʼ();
            } else if (this.ˊ.ॱˋ() == null || this.ˊ.ॱˋ().isFinishing()) {
                czi.ˎ.ˏ("UpdateManagerFragment", "activity error, activity is null or finished!");
                this.ˊ.ˋʼ();
            } else {
                String action = intent.getAction();
                if ("updatemanager.refresh.update.expand.action".equals(action)) {
                    ˋ(intent);
                } else if (ccv.ˋ().equals(action) || ccv.ˊ().equals(action)) {
                    this.ˊ.ˊʻ();
                } else if ("updatemanager.ignore.update.isshow.action".equals(action)) {
                    ˊ();
                } else if ("updatemanager.notrecommend.update.isshow.action".equals(action)) {
                    ˏ();
                } else if ("refresh.update.fragment.broadcast".equals(action)) {
                    if (this.ˊ.ˊ != null) {
                        this.ˊ.ˊ.sendMessage(this.ˊ.ˊ.obtainMessage(1));
                    }
                } else if ("notify.listview.refresh_broadcast".equals(action)) {
                    this.ˊ.ॱʾ();
                }
            }
        }

        private void ˋ(Intent intent) {
            Object stringExtra = intent.getStringExtra("card_packageName");
            if (!TextUtils.isEmpty(stringExtra)) {
                boolean booleanExtra = intent.getBooleanExtra("card_isExpand", false);
                for (chz o_chz : this.ˊ.י.ʻॱ()) {
                    if (o_chz != null) {
                        List<CardBean> ˏ = o_chz.ˏ();
                        if (ˏ != null) {
                            for (CardBean cardBean : ˏ) {
                                if (cardBean instanceof UpdateRecordCardBean) {
                                    boolean z;
                                    if (stringExtra.equals(cardBean.ॱـ())) {
                                        z = booleanExtra;
                                    } else {
                                        z = false;
                                    }
                                    ((UpdateRecordCardBean) cardBean).ॱ(z);
                                }
                            }
                        }
                    }
                }
                this.ˊ.ॱʾ();
            }
        }

        private void ˏ() {
            boolean ॱ = this.ˊ.ᐝ.ॱ(this.ˊ.י);
            this.ˊ.ॱʾ();
            if (ॱ) {
                ॱ(-6);
            }
        }

        private void ॱ(long j) {
            int i = 0;
            for (chz o_chz : this.ˊ.י.ʻॱ()) {
                if (o_chz.ˏ == j) {
                    break;
                }
                i = this.ˊ.י.ॱ(o_chz) + i;
            }
            this.ˊ.ͺˎ.setSelection(i);
        }

        private void ˊ() {
            boolean ˊ = this.ˊ.ᐝ.ˊ(this.ˊ.י);
            this.ˊ.ॱʾ();
            if (ˊ) {
                ॱ(-3);
            }
        }
    };
    private LinearLayout ﾞ;
    private HwButton ﾟ;

    static {
        cjl.ˋ("updatemgr.fragment", UpdateManagerFragment.class);
    }

    public static UpdateManagerFragment ˏ(UpdateMgrFragmentProtocol updateMgrFragmentProtocol) {
        return (UpdateManagerFragment) cjk.ˎ().ˊ(new cjm("updatemgr.fragment", updateMgrFragmentProtocol));
    }

    public void ˊʻ() {
        if (this.ʻˋ != null) {
            new dbe(ॱˋ(), this.ﹳ, this.ﾟ).executeOnExecutor(this.ʻˋ, new HwButton[0]);
        }
    }

    public void ˏ(Bundle bundle) {
        UpdateMgrFragmentProtocol updateMgrFragmentProtocol = (UpdateMgrFragmentProtocol) ˆ();
        boolean z = eqh.ˎ().ˏ() && cep.ˏ();
        this.ʻˊ = z;
        if (updateMgrFragmentProtocol != null) {
            boolean z2;
            this.ˏͺ = ((Request) updateMgrFragmentProtocol.ॱ()).ˋॱ();
            z = ((Request) updateMgrFragmentProtocol.ॱ()).ˎˎ();
            if (this.ʻˊ && z) {
                z = true;
            } else {
                z = false;
            }
            this.ʻˊ = z;
            this.ꞌॱ = ((Request) updateMgrFragmentProtocol.ॱ()).ˋᐝ();
            if ((((Request) updateMgrFragmentProtocol.ॱ()).ˍ() & 2) != 0) {
                z2 = true;
            } else {
                z2 = false;
            }
            this.ꜝ = z2;
        }
        if (!this.ꜝ) {
            ॱˋ(true);
        }
        ᐝॱ(false);
        super.ˏ(bundle);
        this.ᐝ = dbd.ˏ();
        this.ᐝ.ˎ();
        this.ˊ = new dbb(this);
    }

    private void ॱـ() {
        this.ﾞ = (LinearLayout) this.ॱˍ.findViewById(czk$c.ˊᐝ);
        if (!this.ꞌॱ) {
            BaseTitleBean baseTitleBean = new BaseTitleBean();
            baseTitleBean.ॱ(ॱ(g.ˊˋ));
            cje o_cje = new cje();
            o_cje.ˎ(baseTitleBean);
            o_cje.ˋ("back_title");
            this.ʼˋ = cjd.ˋ(ॱˋ(), o_cje);
            if (!(this.ʼˋ == null || this.ʼˋ.ˋ() == null)) {
                this.ﾞ.setVisibility(0);
                LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
                layoutParams.gravity = 3;
                this.ﾞ.addView(this.ʼˋ.ˋ(), layoutParams);
            }
        }
        this.ʹ = this.ॱˍ.findViewById(czk$c.ˏ);
        this.ﹳ = this.ॱˍ.findViewById(czk$c.ˎ);
        this.ﹳ.setBackgroundColor(ᐝॱ().getColor(czk$a.ˊ));
        this.ﾟ = (HwButton) this.ॱˍ.findViewById(czk$c.ˊˋ);
        azb.ˋ(this.ﾟ);
        this.ﾟ.setOnClickListener(new dbc(this) {
            final /* synthetic */ UpdateManagerFragment ˎ;

            {
                this.ˎ = r1;
            }

            public void ॱ(View view) {
                czi.ˎ.ˋ("UpdateManagerFragment", "onClick UpdateAllButton");
                if (dao.ˏ().ˎ() != null) {
                    dao.ˏ().ˎ().ˊ(this.ˎ.ॱˋ(), this.ˎ.ﾟ);
                }
            }
        });
        this.ॱॱ = (LinearLayout) this.ॱˍ.findViewById(czk$c.ʻ);
        this.ꜟॱ = (RelativeLayout) this.ॱˍ.findViewById(czk$c.ॱˋ);
        azb.ˏ(this.ꜟॱ);
        if (this.ʻˊ) {
            this.ﹳॱ = new PreDownloadSwitchStateCard(ॱˋ());
            this.ﹳॱ.ˏ(this.ꜟॱ);
            this.ﹳॱ.ˏ(new BaseDistCardBean());
            return;
        }
        this.ꜟॱ.setVisibility(8);
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.ˊʼ = ॱ(g.ˊˋ);
        Context ॱˋ = ॱˋ();
        if (ॱˋ instanceof czz) {
            this.ꜞॱ = (czz) ॱˋ;
        }
        this.ॱˍ = (ViewGroup) super.ˋ(layoutInflater, viewGroup, bundle);
        ॱـ();
        if (this.י.ˏॱ()) {
            this.ᐝ.ˎ(this.י, this.ʻˊ);
        }
        ٴ();
        י();
        this.ʻˋ = Executors.newFixedThreadPool(1);
        new dbe(ॱˋ, this.ﹳ, this.ﾟ).executeOnExecutor(this.ʻˋ, new HwButton[0]);
        this.ﾟ.setMinimumWidth(epv.ˎ(ॱˋ) / 2);
        return this.ॱˍ;
    }

    public int ߵ() {
        return czk$e.ˎ;
    }

    public void ᐝ() {
        if (this.ʻˋ != null) {
            this.ʻˋ.shutdownNow();
            this.ʻˋ = null;
        }
        super.ᐝ();
    }

    public void onScrollStateChanged(AbsListView absListView, int i) {
        super.onScrollStateChanged(absListView, i);
        if (i == 2) {
            erm.ˏ().ॱ(true);
        } else {
            erm.ˏ().ॱ(false);
        }
    }

    public void ˋ(ViewGroup viewGroup, LayoutInflater layoutInflater) {
        ˎ(viewGroup);
    }

    public void ˌॱ() {
        super.ˌॱ();
        ॱˉ();
    }

    public void ˋʼ() {
        super.ˋʼ();
        try {
            if (!(this.ﹶ == null || ॱˋ() == null)) {
                ActivityUtil.unregisterReceiver(ॱˋ(), this.ﹶ);
            }
        } catch (IllegalArgumentException e) {
            czi.ˎ.ˊ("UpdateManagerFragment", "unregisterDownloadReceiver, exception: " + e.toString());
        }
        try {
            if (!(this.ﹶ == null || ॱˊ() == null)) {
                ll.ˏ(ॱˊ()).ˋ(this.ﹶ);
            }
        } catch (IllegalArgumentException e2) {
            czi.ˎ.ˊ("UpdateManagerFragment", "unregisterDownloadReceiver, exception: " + e2.toString());
        }
        ((czr) dbn.ˎ(czr.class)).ˏ(hashCode() + "UpdateManagerFragment");
    }

    private void ॱˉ() {
        if (ॱˋ() == null) {
            czi.ˎ.ˊ("UpdateManagerFragment", "registerBroadCast, context == null");
            return;
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ccv.ˋ());
        intentFilter.addAction(ccv.ˊ());
        ActivityUtil.registerReceiver(ॱˋ(), intentFilter, this.ﹶ);
        intentFilter = new IntentFilter();
        intentFilter.addAction("updatemanager.refresh.update.expand.action");
        intentFilter.addAction("updatemanager.ignore.update.isshow.action");
        intentFilter.addAction("updatemanager.notrecommend.update.isshow.action");
        intentFilter.addAction("refresh.update.fragment.broadcast");
        intentFilter.addAction("notify.listview.refresh_broadcast");
        ll.ˏ(ॱˊ()).ˏ(this.ﹶ, intentFilter);
        ((czr) dbn.ˎ(czr.class)).ˎ(hashCode() + "UpdateManagerFragment", new czx(this) {
            final /* synthetic */ UpdateManagerFragment ˊ;

            {
                this.ˊ = r1;
            }

            public void ˋ(int i) {
                if (this.ˊ.ˊ != null) {
                    this.ˊ.ˊ.sendMessage(this.ˊ.ˊ.obtainMessage(1));
                }
            }

            public void ˎ(int i) {
            }

            public void ˏ(String str) {
            }

            public void ˏ(String str, ckm o_ckm) {
            }

            public void ˋ() {
            }
        });
    }

    public CardListAdapter ˎ(Context context, cia o_cia) {
        return new UpdateCardListAdapter(context, o_cia);
    }

    public void ॱ(a aVar, ResponseBean responseBean, NetworkRemindBar networkRemindBar) {
    }

    public void ॱ(chd o_chd) {
    }

    public void ˋ(BaseRequest o_cvu, ResponseBean responseBean) {
        super.ˋ(o_cvu, responseBean);
        this.ᐝ.ˋ(this.י);
        ٴ();
    }

    public void onConfigurationChanged(Configuration configuration) {
        chm.ॱ().ˋ();
        super.onConfigurationChanged(configuration);
    }

    public void ٴ() {
        if (this.ॱॱ == null || this.ꜟॱ == null || this.ͺˎ == null || this.ʹ == null || this.י == null) {
            czi.ˎ.ˋ("UpdateManagerFragment", "showDefaultView error, defaultLayout = " + this.ॱॱ + ", preDldDefaultLayout = " + this.ꜟॱ + ", listView = " + this.ͺˎ);
        } else if (ॱˌ()) {
            if (this.ॱॱ.getVisibility() != 8) {
                this.ॱॱ.setVisibility(8);
            }
            if (this.ꜟॱ.getVisibility() != 8) {
                this.ꜟॱ.setVisibility(8);
            }
            if (this.ʹ.getVisibility() != 0) {
                this.ʹ.setVisibility(0);
            }
        } else {
            this.ॱॱ.setVisibility(0);
            if (this.ʻˊ) {
                this.ꜟॱ.setVisibility(0);
            } else {
                this.ꜟॱ.setVisibility(8);
            }
            this.ʹ.setVisibility(8);
        }
    }

    private boolean ॱˌ() {
        boolean z;
        if (this.ʻˊ) {
            z = true;
        } else {
            z = false;
        }
        if (this.י.ˊॱ() > z) {
            return true;
        }
        return false;
    }

    public void י() {
        if (this.ꜞॱ != null) {
            this.ꜞॱ.ॱ(this.ᐝ.ॱ());
        } else {
            ॱˑ();
        }
    }

    private void ॱˑ() {
        if (ॱˋ() == null || ॱˋ().isFinishing()) {
            czi o_czi = czi.ˎ;
            String str = "UpdateManagerFragment";
            StringBuilder append = new StringBuilder().append("getActivity() = ").append(ॱˋ()).append(", getActivity().isFinishing() = ");
            boolean z = ॱˋ() != null && ॱˋ().isFinishing();
            o_czi.ˋ(str, append.append(z).toString());
            return;
        }
        String ॱ = ॱ(g.ˊˋ);
        if (this.ʼˋ != null) {
            BaseTitleBean ˎ = this.ʼˋ.ˎ();
            ˎ.ॱ(ॱ);
            this.ʼˋ.ॱ(ˎ);
        }
    }

    public void ߺ() {
        if (this.ॱॱ != null && this.ꜟॱ != null && this.ͺˎ != null && ॱˋ() != null && !ॱˋ().isFinishing()) {
            this.ᐝ.ˏ(this.י);
        }
    }

    public void ॱʾ() {
        if (this.ͺˎ == null) {
            czi.ˎ.ˏ("UpdateManagerFragment", "notifyDataSetChanged listView null");
            return;
        }
        CardListAdapter cardListAdapter;
        ((LinearLayout.LayoutParams) this.ͺˎ.getLayoutParams()).setMargins(0, 0, 0, ContentManager.getInstant().getContext().getResources().getDimensionPixelSize(czk$b.ˊ));
        ListAdapter adapter = this.ͺˎ.getAdapter();
        if (adapter instanceof HeaderViewListAdapter) {
            adapter = ((HeaderViewListAdapter) adapter).getWrappedAdapter();
            cardListAdapter = adapter instanceof CardListAdapter ? (CardListAdapter) adapter : null;
        } else {
            cardListAdapter = (CardListAdapter) adapter;
        }
        if (cardListAdapter != null) {
            cardListAdapter.notifyDataSetChanged();
        }
    }
}
